package com.dragon.myapplication.retrofit

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.TextView
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.dragon.myapplication.R
import com.dragon.myapplication.databinding.ActivityMyKotlinBinding

class MyKotlinActivity : AppCompatActivity() {

    private lateinit var tv:TextView
    private lateinit var binding:ActivityMyKotlinBinding
    private var num:Int = 0

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_my_kotlin)
        tv = findViewById(R.id.tv)
        binding = DataBindingUtil.setContentView(this,R.layout.activity_my_kotlin)

        val viewModel = ViewModelProvider(
            this
        ).get(MyViewModel::class.java)
        viewModel.number.observe(this, Observer { tv.text = it.toString() })


        binding.button2.setOnClickListener {
            viewModel.modifyNumber(1)
        }
        binding.button3.setOnClickListener {
            viewModel.modifyNumber(-1)
        }
    }
}